/*
 * Copyright (c) 2014. kupat Corporation. All rights reserved.
 *  see statement on http://www.kupat.cn.
 */
package com.kfgj.hkp.common.dataaccess.dialect;

/**
 * Created by liwensihan on 2014/11/8.
 *
 * @author liwensihan
 */
public abstract class AbstractDialect {

    public boolean supportsLimit(){
        return false;
    }

    public boolean supportsLimitOffset() {
        return supportsLimit();
    }

    /**
     * 将sql变成分页sql语句,直接使用offset,limit的值作为占位符.
     * @param sql sql语句
     * @param offset 分页数据起始offset
     * @param limit 分页大小
     * @return 分页sql
     */
    public String getLimitString(String sql, int offset, int limit) {
        return getLimitString(sql,offset,Integer.toString(offset),limit,Integer.toString(limit));
    }

    /**
     *  将sql变成分页sql语句,提供将offset及limit使用占位符(placeholder)替换.
     * <pre>
     * 如mysql
     * dialect.getLimitString("select * from user", 12, ":offset",0,":limit") 将返回
     * select * from user limit :offset,:limit
     * </pre>
     * @param sql sql语句
     * @param offset 分页数据起始offset
     * @param offsetPlaceholder sql语句中offset占位符
     * @param limit 分页大小
     * @param limitPlaceholder sql语句中limit占位符
     * @return 包含占位符的分页sql
     */
    public abstract String getLimitString(String sql, int offset,String offsetPlaceholder, int limit,String limitPlaceholder);

}
